﻿Imports System.Data.SqlClient
Public Class en_members_merchantdetailinfo
    Inherits System.Web.UI.Page
    Private sSQL As String
    Private objrd As SqlDataReader = Nothing
    Private objfind As New GetData
    Private ps As New PreparedStatement(sSQL)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Session("uid") <> Nothing And Session("uid") <> "") Then
            Dim legalPerson, capital, employNum, sale_volume, import_volume, export_volume, factory_area, company_type,
                mainMarket, mainBrand, companyUrl, mainCustomer, zipCode, bank, bankCode, companyPhone, companyFax As String
            Dim createDate As String
            Dim isOEM As Boolean
            Dim memberId, strErr, companyId, mainMarketStr As String
            companyId = ""
            mainMarketStr = ""
            strErr = ""
            memberId = Session("uid")
            If (Request("submit") <> Nothing And Request("submit") <> "") Then
                legalPerson = Request("c_legal_person")
                capital = Request("c_capital")
                'createDate = Convert.ToDateTime(Request("c_create_date"))
                If (Request("c_create_date") = Nothing Or Request("c_create_date").Trim = "") Then
                    createDate = "1753-01-01"
                Else
                    createDate = Request("c_create_date")
                End If
                employNum = Request("c_employ_num")
                sale_volume = Request("c_sale_volume")
                import_volume = Request("c_import_volume")
                export_volume = Request("c_export_volume")
                If (Request("c_isoem").ToString = "1") Then
                    isOEM = True
                ElseIf (Request("c_isoem").ToString = "0") Then
                    isOEM = False
                End If
                factory_area = Request("c_factory_area")
                company_type = Request("c_company_type")
                If (Me.lmarket.Checked) Then
                    mainMarketStr &= "{china mainland}"
                End If
                If (Me.hkmarket.Checked) Then
                    mainMarketStr &= "{Hongkong}"
                End If
                If (Me.namarket.Checked) Then
                    mainMarketStr &= "{Northern America}"
                End If
                If (Me.samarket.Checked) Then
                    mainMarketStr &= "{Southern America}"
                End If
                If (Me.wumarket.Checked) Then
                    mainMarketStr &= "{Western Eoupe}"
                End If
                If (Me.eumarket.Checked) Then
                    mainMarketStr &= "{Eastern Eoupe}"
                End If
                If (Me.eamarket.Checked) Then
                    mainMarketStr &= "{Eastern Asia}"
                End If
                If (Me.esamarket.Checked) Then
                    mainMarketStr &= "{Southeast Asia}"
                End If
                If (Me.memarket.Checked) Then
                    mainMarketStr &= "{Middle East}"
                End If
                If (Me.amarket.Checked) Then
                    mainMarketStr &= "{Africa}"
                End If
                If (Me.aumarket.Checked) Then
                    mainMarketStr &= "{Oceania}"
                End If
                If (Me.gmarket.Checked) Then
                    mainMarketStr &= "{Global}"
                End If
                mainMarket = mainMarketStr

                mainBrand = Request("c_main_brand")
                companyUrl = Request("c_company_url")
                mainCustomer = Request("c_main_customer")
                zipCode = Request("c_zipcode")
                bank = Request("c_bank")
                companyPhone = Request("c_company_phone")
                bankCode = Request("c_bank_code")
                companyFax = Request("c_company_fax")

                ps.strSql = "select mi.* from member m,merchant_info mi where m.company_id=mi.company_id and mi.lang_flag='en' and m.GAPortal_ID=@memberId"
                ps.parameters.Clear()
                ps.addParameter("memberId", memberId)
                Dim conn As SqlConnection = objfind.getConn()

                objrd = objfind.dr(ps, strErr, conn, objrd)
                If (strErr = "" And objrd.Read()) Then
                    ps.strSql = "update merchant_info set legal_person = @legal_person, create_date=@createDate, capital=@capital ,employnum=@employnum,sale_volume=@sale_volume,import_volume=@import_volume ," & _
                        "export_volume=@export_volume,isOEM=@isOEM,factory_area=@factory_area,company_type=@company_type,main_market=@main_market,main_brand=@main_brand,company_url=@company_url, " & _
                        "main_customers=@main_customers,zipcode=@zipcode,bank=@bank,company_phone=@company_phone,bank_code=@bank_code,company_fax=@company_fax where id=@id"
                    ps.parameters.Clear()
                    ps.addParameter("legal_person", legalPerson)
                    ps.addParameter("capital", capital)
                    ps.addParameter("createDate", createDate)
                    ps.addParameter("employnum", employNum)
                    ps.addParameter("sale_volume", sale_volume)
                    ps.addParameter("import_volume", import_volume)
                    ps.addParameter("export_volume", export_volume)
                    ps.addParameter("isOEM", isOEM)
                    ps.addParameter("factory_area", factory_area)
                    ps.addParameter("company_type", company_type)
                    ps.addParameter("main_market", mainMarket)
                    ps.addParameter("main_brand", mainBrand)
                    ps.addParameter("company_url", companyUrl)
                    ps.addParameter("main_customers", mainCustomer)
                    ps.addParameter("zipcode", zipCode)
                    ps.addParameter("bank", bank)
                    ps.addParameter("company_phone", companyPhone)
                    ps.addParameter("bank_code", bankCode)
                    ps.addParameter("company_fax", companyFax)
                    ps.addParameter("id", objrd.Item("id"))
                    objfind.es(ps, strErr)
                Else
                    ps.strSql = "select * from merchant where owner_id =@ownerId"
                    ps.addParameter("ownerId", memberId)
                    objrd = objfind.dr(ps, strErr, conn, objrd)
                    If (objrd.Read()) Then
                        companyId = objrd.Item("company_id")
                    End If
                    ps.strSql = "insert into merchant_info （id,company_id,legal_person ,create_date,capital ,create_date,employnum,sale_volume,import_volume ,export_volume,isOEM," & _
                        "factory_area,company_type,main_market,main_brand,company_url,main_customers,zipcode,bank,company_phone,bank_code,company_fax） " & _
                        "values(@id,@companyId @legal_person,@createDate @capital ,@create_date,@employnum,@sale_volume,@import_volume ," & _
                        "@export_volume,@isOEM,@factory_area,@company_type,@main_market,@main_brand,@company_url, " & _
                        "@main_customers,@zipcode,@bank,@company_phone,@bank_code,@company_fax)"
                    ps.parameters.Clear()
                    ps.addParameter("companyId", companyId)
                    ps.addParameter("id", System.Guid.NewGuid().ToString())
                    ps.addParameter("legal_person", legalPerson)
                    ps.addParameter("capital", capital)
                    ps.addParameter("createDate", createDate)
                    ps.addParameter("employnum", employNum)
                    ps.addParameter("sale_volume", sale_volume)
                    ps.addParameter("import_volume", import_volume)
                    ps.addParameter("export_volume", export_volume)
                    ps.addParameter("isOEM", isOEM)
                    ps.addParameter("factory_area", factory_area)
                    ps.addParameter("company_type", company_type)
                    ps.addParameter("main_market", mainMarket)
                    ps.addParameter("main_brand", mainBrand)
                    ps.addParameter("company_url", companyUrl)
                    ps.addParameter("main_customers", mainCustomer)
                    ps.addParameter("zipcode", zipCode)
                    ps.addParameter("bank", bank)
                    ps.addParameter("company_phone", companyPhone)
                    ps.addParameter("bank_code", bankCode)
                    ps.addParameter("company_fax", companyFax)
                    objfind.es(ps, strErr)
                End If
                objfind.closeConn(conn)

            Else
                sSQL = "select mi.*,mm.company_mode,mm.company_major from member m,merchant mm,merchant_info mi where m.company_id=mi.company_id and mm.company_id=m.company_id and mi.lang_flag='en' and m.GAPortal_ID=@memberId"
                ps.strSql = sSQL
                ps.parameters.Clear()
                ps.addParameter("memberId", memberId)
                Dim conn As SqlConnection = objfind.getConn()

                objrd = objfind.dr(ps, strErr, conn, objrd)
                If (strErr = "" And objrd.Read()) Then
                    c_legal_person.Text = objrd("legal_person").ToString
                    c_capital.Text = objrd("capital").ToString
                    If (objrd("create_date").ToString <> Nothing And objrd("create_date").ToString <> "") Then
                        c_create_date.Text = Format(objrd("create_date"), "yyyy-MM-dd").ToString
                    Else
                        c_create_date.Text = ""
                    End If
                    c_employ_num.Items.FindByValue(objrd("employnum").ToString).Selected = True
                    c_sale_volume.Items.FindByValue(objrd("sale_volume").ToString).Selected = True
                    c_import_volume.Items.FindByValue(objrd("import_volume").ToString).Selected = True
                    c_export_volume.Items.FindByValue(objrd("export_volume").ToString).Selected = True
                    If (objrd("isoem").ToString.Trim().ToLower() = "false") Then
                        c_isoem.Items.FindByValue("0").Selected = True
                    ElseIf (objrd("isoem").ToString.Trim().ToLower() = "true") Then
                        c_isoem.Items.FindByValue("1").Selected = True
                    End If
                    c_factory_area.Text = objrd("factory_area").ToString
                    c_company_type.Items.FindByValue(objrd("company_type").ToString).Selected = True
                    If (objrd("main_market").ToString.Contains("china mainland")) Then
                        Me.lmarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Hongkong")) Then
                        Me.hkmarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Northern America")) Then
                        Me.namarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Southern America")) Then
                        Me.samarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Western Eoupe")) Then
                        Me.wumarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Eastern Eoupe")) Then
                        Me.eumarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Eastern Asia")) Then
                        Me.eamarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Southeast Asia")) Then
                        Me.esamarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Middle East")) Then
                        Me.memarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Africa")) Then
                        Me.amarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Oceania")) Then
                        Me.aumarket.Checked = True
                    End If
                    If (objrd("main_market").ToString.Contains("Global")) Then
                        Me.gmarket.Checked = True
                    End If
                    c_main_brand.Text = objrd("main_brand").ToString
                    c_company_url.Text = objrd("company_url").ToString
                    c_main_customer.Text = objrd("main_customers").ToString
                    c_zipcode.Text = objrd("zipcode").ToString
                    c_bank.Text = objrd("bank").ToString
                    c_company_phone.Text = objrd("company_phone").ToString
                    c_bank_code.Text = objrd("bank_code").ToString
                    c_company_fax.Text = objrd("company_fax").ToString
                End If
                objfind.closeConn(conn)

            End If
        Else
            Response.Redirect("../login.aspx")
        End If
    End Sub

End Class